#include "dominion.h"
#include <stdio.h>
#include "rngs.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>


int getFavoriteKingdomCard(int kingdomCards[]){
	int min = 0;
	int max = 9;
	double scaled = (double)rand()/RAND_MAX;
	int i = (max - min +1)*scaled + min;
	return kingdomCards[i];
}

int getRandomNumOfPlayers(){
	int min = 2;
	int max = 4;
	double scaled = (double)rand()/RAND_MAX;
	return (max - min +1)*scaled + min;
}

int getRandomKingdomCard(){
	int min = 7;
	int max = 26;
	double scaled = (double)rand()/RAND_MAX;
	return (max - min +1)*scaled + min;
}

int hasKingdomCard(int array[], int card){
	for(int i = 0; i < 10; i++){
		if (array[i] == card){
				return 1;
		}
	}
	return 0;
}

void pickRandomKingdomCards(int nums[]){
	for(int i = 0; i < 10; i++){
		int randCard = getRandomKingdomCard();
		while(1){	
			if (hasKingdomCard(nums, randCard)){
				randCard = getRandomKingdomCard();
				continue;
			}
			break;
   		}
		nums[i] = randCard;
	}
}

void printArray(int nums[], int length){
	for(int i = 0; i < length; i++){
		printf("%d", nums[i]);
		if( i < length - 1){
			printf(",");
		}else{
			printf("\n");
		}
	}
}

int main(int argc, char *argv[])
{
  // random seed
  srand(time(NULL));

  // Pick a random number of players in range 2, 4 inclusive
  int numPlayers = getRandomNumOfPlayers();
  printf("Number of players: %d\n", numPlayers);
    
  // Pick 10 random, unique kingdom car
  int kingdomCards[10];
  pickRandomKingdomCards(kingdomCards);
  printf("Kingdom cards: ");
  printArray(kingdomCards, 10);

  // Pick a random seed for init
  int randSeed = rand();
  printf("Random seed for initializeGame: %d\n", randSeed);

  // Assign favorite kingdom cards
  int playerFavorites[numPlayers];
  for(int p = 0; p < numPlayers; p++){
  	playerFavorites[p] = getFavoriteKingdomCard(kingdomCards);
  	printf("Player %d's favorite kingdom card: %d\n", p, playerFavorites[p]);
  }

	
  return 0;
}

